From cb317554f8665bf1ce6aa18d02b12d19b0008269 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 11 Jan 2022 13:14:44 +0100 Subject: chore: add toc and widgets to subject pages --- src/pages/sujet/[slug].tsx | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) (limited to 'src/pages/sujet/[slug].tsx') diff --git a/src/pages/sujet/[slug].tsx b/src/pages/sujet/[slug].tsx index 71d0f42..167bfc0 100644 --- a/src/pages/sujet/[slug].tsx +++ b/src/pages/sujet/[slug].tsx @@ -2,39 +2,63 @@ import { getLayout } from '@components/Layouts/Layout'; import PostPreview from '@components/PostPreview/PostPreview'; import { t } from '@lingui/macro'; import { NextPageWithLayout } from '@ts/types/app'; -import { SubjectProps } from '@ts/types/taxonomies'; +import { SubjectProps, ThematicPreview } from '@ts/types/taxonomies'; import { loadTranslation } from '@utils/helpers/i18n'; import { GetStaticPaths, GetStaticProps, GetStaticPropsContext } from 'next'; import { ParsedUrlQuery } from 'querystring'; -import styles from '@styles/pages/Listing.module.scss'; +import styles from '@styles/pages/Page.module.scss'; import { getAllSubjectsSlug, getSubjectBySlug, } from '@services/graphql/queries'; import PostHeader from '@components/PostHeader/PostHeader'; import { ArticleMeta } from '@ts/types/articles'; +import ToC from '@components/ToC/ToC'; +import { RelatedThematics, TopicsList } from '@components/Widget'; +import { useRef } from 'react'; const Subject: NextPageWithLayout = ({ subject }) => { + const relatedThematics = useRef([]); + + const updateRelatedThematics = (newThematics: ThematicPreview[]) => { + newThematics.forEach((thematic) => { + const thematicIndex = relatedThematics.current.findIndex( + (relatedThematic) => relatedThematic.id === thematic.id + ); + const hasThematic = thematicIndex === -1 ? false : true; + + if (!hasThematic) relatedThematics.current.push(thematic); + }); + }; + const getPostsList = () => { - return [...subject.posts].reverse().map((post) => ( -
  • - -
  • - )); + return [...subject.posts].reverse().map((post) => { + updateRelatedThematics(post.thematics); + + return ( +
  • + +
  • + ); + }); }; const meta: ArticleMeta = { + dates: subject.dates, website: subject.officialWebsite, }; return ( -
    +
    +
    {subject.posts.length > 0 && ( @@ -44,6 +68,10 @@ const Subject: NextPageWithLayout = ({ subject }) => { )}
    +
    ); }; -- cgit v1.2.3